import moment from 'moment'
let defaultTime = moment(new Date()).format('YYYY-MM-DD')

export function getFullTime (time) {
  return `${defaultTime} ${time}:00`
}

export function getTotalTime (timeArr = ['08:00', '20:00']) {
  return moment(`${defaultTime} ${timeArr[1]}:00`).diff(`${defaultTime} ${timeArr[0]}:00`)
}

export function timeToX (time, totalX, timeArr = ['08:00', '20:00']) {
  let totalTime = getTotalTime(timeArr)
  let timeX = moment(getFullTime(time)).diff(getFullTime(timeArr[0]))
  return (timeX / totalTime) * totalX
}

export function xToFormatTime (x, totalX, timeArr = ['08:00', '20:00']) {
  let totalTime = getTotalTime(timeArr)
  let startTime = new Date(getFullTime(timeArr[0])).getTime()
  return moment(startTime + (x / totalX) * totalTime).format('HH:mm')
}

export function xToTime (x, totalX, timeArr = ['08:00', '20:00']) {
  let totalTime = getTotalTime(timeArr)
  let startTime = new Date(getFullTime(timeArr[0])).getTime()
  return startTime + (x / totalX) * totalTime
}

export function getTimePercent (time, timeArr = ['08:00', '20:00']) {
  let totalTime = getTotalTime(timeArr)
  let diffTime = moment(getFullTime(time)).diff(getFullTime(timeArr[0]))
  return diffTime / totalTime
}
